<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      label-width="90px"
    >
      <el-form-item label="产出批次号" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入产出批次号"
          clearable
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="报工人" prop="person">
        <el-input
          v-model="queryParams.person"
          placeholder="请选择报工人"
          clearable
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item label="时间段" prop="date">
        <el-date-picker
          v-model="queryParams.date"
          style="width: 240px"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="YYYY-MM-DD"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="tableData"
      border
      style="width: 100%; margin-top: 10px"
    >
      <el-table-column label="工序" prop="prodDate" />
      <el-table-column label="投料批号" prop="scheduleName" />
      <el-table-column label="投入数量(米)" prop="workGroup" />
      <el-table-column label="开始时间" prop="monitorName" />
      <el-table-column label="结束时间" prop="createTime" />
      <el-table-column label="产出批号" prop="createTime" />
      <el-table-column label="产出数量(米)" prop="prodName" />
      <el-table-column label="有效数量(米)" prop="prodName" />
      <el-table-column label="损耗(米)" prop="prodName" />
      <el-table-column label="良率" prop="prodName" />
      <el-table-column label="投产比" prop="unit" />
      <el-table-column label="不良描述" prop="unit" />
      <el-table-column label="线边仓" prop="unit" />
      <el-table-column label="库位" prop="unit" />
      <el-table-column label="操作人" prop="unit" />
      <el-table-column label="执行时间" prop="unit" />
      <el-table-column label="状态" prop="status"
        ><template #default="scope">
          <dict-tag :options="change_shifts_status" :value="scope.row.status" />
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="Data">
import { listChangeShifts } from "@/api/productionMgt/changeShifts";
const { proxy } = getCurrentInstance();
const tableData = ref([]);
const props = defineProps(["datas"]);
const { datas } = toRefs(props);
const loading = ref(false);
const dateRange = ref([]);
const { change_shifts_status } = proxy.useDict("change_shifts_status");
const total = ref(0);
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 999,
    name: undefined,
  },
});
const { queryParams, form } = toRefs(data);
watch(
  datas,
  (val) => {
    console.log(val, "=====openOrder");
    // getList();
  },
  { immediate: true, deep: true }
);

function getList() {
  loading.value = true;
  let newForm = JSON.parse(JSON.stringify(queryParams.value));
  if (queryParams.value?.date?.length) {
    newForm.planStartTime = queryParams.value.date[0];
    newForm.planEndTime = queryParams.value.date[1];
    delete newForm.date;
  }
  newForm.workOrderCode = datas.value?.workOrderCode;
  listChangeShifts(proxy.addDateRange(newForm)).then((response) => {
    tableData.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  dateRange.value = [];
  proxy.resetForm("queryRef");
  handleQuery();
}

onMounted(async () => {});
</script>
<style lang="scss" scoped></style>
